home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Resound / SoundTable.m < prev    next >
Encoding:
Text File  |  1992-06-13  |  3.7 KB  |  248 lines

  1.  
  2. #import "SoundTable.h"
  3. #import "Imports.h"
  4.  
  5. #define MAX_NUMBER_OF_SOUNDS 256
  6.  
  7. @implementation SoundTable
  8.  
  9. - (int) NewItem:ThisSound: 
  10.                 ThisSoundView: 
  11.                 ThisWindow:
  12.                 (char*) ThisFileName:
  13.                 (BOOL) ItsUntitled
  14. {
  15.     if (CurrentNumber<MAX_NUMBER_OF_SOUNDS) {
  16.         ++CurrentNumber;
  17.         SoundID[CurrentNumber]=ThisSound;
  18.         SoundViewID[CurrentNumber]=ThisSoundView;
  19.         WindowID[CurrentNumber]=ThisWindow;
  20.         
  21.         String[CurrentNumber]=[StringTable alloc];
  22.         [String[CurrentNumber] init];
  23.         [String[CurrentNumber] ChangeString:ThisFileName];
  24.         
  25.         SoundUntitled[CurrentNumber]=ItsUntitled;
  26.         return CurrentNumber;
  27.     }
  28.     else return 0;
  29. }
  30.  
  31. - init
  32. {
  33.     int x;
  34.     [super init];
  35.     for (x=1;x<=MAX_NUMBER_OF_SOUNDS;x++)
  36.         {SoundID[x]=NULL;
  37.          SoundViewID[x]=NULL;
  38.          WindowID[x]=NULL;
  39.          SoundChanged[x]=NO;
  40.          String[x]=NULL;
  41.          SoundUntitled[x]=NO;
  42.         }
  43.     StartPosX=250;
  44.     StartPosY=450;
  45.     PosX=StartPosX;
  46.     PosY=StartPosY;
  47.     CurrentNumber=0;
  48.     Current=CurrentNumber;
  49.     WindowPosCount=0;
  50.     return self;
  51. }
  52.  
  53. - ReturnSound
  54. {
  55.     return SoundID[Current];
  56. }
  57.  
  58. - SoundEdited
  59. {
  60.     SoundChanged [Current]=YES;
  61.     return self;
  62. }
  63.  
  64. - ReturnWindow
  65. {
  66.     return WindowID[Current];
  67. }
  68.  
  69. - (BOOL) FindWindow: (id) ThisWindow
  70. {
  71.     int n;
  72.     int theone=0;
  73.     for (n=1;n<=CurrentNumber;n++) {
  74.         if (WindowID[n]==ThisWindow) theone=n;
  75.         }
  76.     if (!(theone==0)) Current=theone;
  77.     return (BOOL) theone;
  78. }
  79.  
  80. - (BOOL) Next
  81. {
  82.     if ([self Total])
  83.         {++Current;
  84.          if (Current>CurrentNumber) Current=1;
  85.         return YES;}
  86.     else return NO;
  87. }
  88.  
  89. - SetSound: ThisSound
  90. {
  91.     SoundID[Current]=ThisSound;
  92.     return self;
  93. }
  94.  
  95. - NewWindowPos
  96. {
  97.     if (WindowPosCount<10)
  98.         {
  99.         PosX=StartPosX+WindowPosCount*22;
  100.         PosY=StartPosY-WindowPosCount*24;
  101.         }
  102.     else
  103.         {
  104.         PosX=StartPosX-150+(WindowPosCount-10)*22;
  105.         PosY=StartPosY-(WindowPosCount-10)*24;
  106.         }
  107.     WindowPosCount++;
  108.     if (WindowPosCount>19) {WindowPosCount=0;}
  109.     return self;
  110. }
  111.  
  112. - (int) WindowPosX
  113. {
  114.     return PosX;
  115. }
  116.  
  117. - (int) WindowPosY
  118. {
  119.     return PosY;
  120. }
  121.  
  122. - Delete
  123. {
  124.     int n;
  125.     if ([self Total]) 
  126.         {
  127.         [String[Current] free];
  128.         for (n=Current+1;n<=CurrentNumber;n++)
  129.             {
  130.              SoundID[n-1]=SoundID[n];
  131.              SoundViewID[n-1]=SoundViewID[n];
  132.              WindowID[n-1]=WindowID[n];
  133.              SoundChanged[n-1]=SoundChanged[n];
  134.              String[n-1]=String[n];
  135.              SoundUntitled[n-1]=SoundUntitled[n];
  136.             }
  137.         CurrentNumber--;
  138.         [self Previous];
  139.     }
  140.     return self;
  141. }
  142.  
  143. - (BOOL) Previous
  144. {
  145.     if ([self Total])
  146.         {--Current;
  147.          if (Current==0) Current=CurrentNumber;
  148.         return YES;}
  149.     else return NO;
  150. }
  151.  
  152. - (BOOL) FindSoundView:(id) ThisSoundView
  153. {
  154.     int n;
  155.     int theone=0;
  156.     for (n=1;n<=CurrentNumber;n++) {
  157.         if (SoundViewID[n]==ThisSoundView) theone=n;
  158.         }
  159.     if (!(theone==0)) Current=theone;
  160.     return (BOOL) theone;
  161. }
  162.  
  163. - ReturnSoundView
  164. {
  165.     return SoundViewID[Current];
  166. }
  167.  
  168. - SetWindow: ThisWindow
  169. {
  170.     WindowID[Current]=ThisWindow;
  171.     return self;
  172. }
  173.  
  174. - SetSoundView: ThisSoundView
  175. {
  176.     SoundViewID[Current]=ThisSoundView;
  177.     return self;
  178. }
  179.  
  180. - (BOOL) FindSound: ThisSound
  181. {
  182.     int n;
  183.     int theone=0;
  184.     for (n=1;n<=CurrentNumber;n++) 
  185.         {
  186.         if (SoundID[n]==ThisSound) theone=n;
  187.         }
  188.     if (!(theone==0)) Current=theone;
  189.     return (BOOL) theone;
  190. }
  191.  
  192. - (int) Total
  193. {
  194.     return CurrentNumber;
  195. }
  196.  
  197. - SoundReset
  198. {
  199.     SoundChanged [Current]=NO;
  200.     return self;
  201. }
  202.  
  203. - (BOOL) FindChangedSound
  204. {
  205.  
  206.     BOOL foundit=NO;
  207.     int n;
  208.     int theone=0;
  209.     for (n=1;n<=CurrentNumber;n++) 
  210.         {
  211.         if ((SoundChanged[n]==YES)&&(!foundit))
  212.             {
  213.             theone=n;
  214.             foundit=YES;
  215.             }
  216.         }
  217.     if (!(theone==0)) 
  218.     {
  219.     Current=theone;
  220.     theone=1;
  221.     }
  222.     return (BOOL) theone;
  223. }
  224.  
  225. - (char*) ReturnFileName
  226. {
  227.     return [String[Current] ReturnString];
  228. }
  229.  
  230. - SetFileName: (char*) ThisFileName
  231. {
  232.     [String[Current] ChangeString:ThisFileName];
  233.     return self;
  234. }
  235.  
  236. - (BOOL) IsSoundChanged
  237. {
  238.     return SoundChanged[Current];
  239. }
  240.  
  241. - (BOOL) ReturnUntitled
  242. {
  243.     return SoundUntitled[Current];
  244. }
  245.  
  246.  
  247. @end
  248.